package view;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import controller.CustomEvent;
import controller.EventHandler;
import controller.IOPanelEventHandler;
/**
 * A class to hold all of the buttons and functionality for I/O of the program.
 * @author Daniel Bond, Gideon Pyzer, Mohammed Abdullah, Marvin Crawford
 */
@SuppressWarnings("serial")
public class IOPanel extends JPanel{	
	private JButton btnExport;
	private JButton btnPrint;
	private JButton btnImport;
	private JButton btnBack;
	private JLabel lblCoordinates;
	private EventHandler eventHandler;
	public IOPanel(){
		btnExport = new JButton("Export");
		btnPrint = new JButton("Print");
		btnImport = new JButton("Import");
		btnBack = new JButton("Back");
		lblCoordinates = new JLabel();
		this.add(btnImport, FlowLayout.LEFT);
		this.add(btnExport, FlowLayout.LEFT);
		this.add(btnPrint, FlowLayout.LEFT);
		this.add(btnBack, FlowLayout.LEFT);
		this.add(lblCoordinates, FlowLayout.LEFT);
		this.add(new BNFLink());
		this.eventHandler = new IOPanelEventHandler();
		btnPrint.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("presPrint", IOPanel.this);
				IOPanel.this.eventHandler.createEvent(event);
			}
		});
		btnExport.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("presExport", IOPanel.this);
				IOPanel.this.eventHandler.createEvent(event);
			}
		});
		btnImport.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("presImport", IOPanel.this);
				IOPanel.this.eventHandler.createEvent(event);
			}
		});
		btnBack.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("back", IOPanel.this);
				IOPanel.this.eventHandler.createEvent(event);
			}
		});		
	}
	/**
	 * disables the two buttons on the GUI and the export item in the File menu.
	 */
	public void setGreyed(){
		btnPrint.setEnabled(false);
		btnExport.setEnabled(false);
		btnBack.setEnabled(false);
	}
	/**
	 * enables the two buttons on the GUI and the export item in the File menu.
	 */
	public void setUsable(){
		btnPrint.setEnabled(true);
		btnExport.setEnabled(true);
		btnImport.setEnabled(true);
		btnBack.setEnabled(true);
	}
	/**
	 * Set the text at the bottom for the co-ordinates
	 * @param text
	 */
	public void setCoords(String text){
		lblCoordinates.setText(text);
	}
}